/**
 * 敌机对象
 * 
 * */
function Enemy({width,height,x,y,img,speed}){
	Role.call(this,{width,height,x,y});
	this.img=img;
	this.speed=speed;
	this.creataDom();
}
//原型链继承
Enemy.prototype=Object.create(Role.prototype);

//创建DOM元素
Enemy.prototype.creataDom=function(){
	//创建dom元素节点
	this.element=document.createElement("div");
	//设置css属性
	this.element.style.width=this.width+"px";
	this.element.style.height=this.height+"px";
	this.element.style.background=`url(${this.img})`;
	this.element.style.position="absolute";
	this.element.style.left=this.x+"px";
	this.element.style.top=this.y+"px";
	//该创建的对象调用map中addRole方法
	Map.addRole(this);
}
//重写方法
Enemy.prototype.move=function(){
	//敌机是否还活着
	if(!this.isAlive){//标记为true则往后执行，false为退出
		return;
	}
	//移动过程中修改y坐标
	this.y+=this.speed;
	//判断如果超出了地图就移除节点
	if(this.y>=Map.height){
		this.isAlive=false;//标记超出范围
		this.element.parentNode.removeChild(this.element);
		return;
	}
	//修改css样式
	this.element.style.top=this.y+"px";
}
//创建工厂
const EnemyFactory={
	createEnemy:function(type){
		//小型敌机
		if(type==="small"){
			return new Enemy({
				width:34,		
				height:24,
				x:random(0,Map.width-34),
				y:0,
				img:"images/small_fly.png",
				speed:3
			});
			
		}
		//中型敌机
		if(type==="middle"){
			return new Enemy({
				width:46,		
				height:60,
				x:random(0,Map.width-46),
				y:0,
				img:"images/mid_fly.png",
				speed:2
			});
		}
		//大型敌机
		if(type==="big"){
			return new Enemy({
				width:110,		
				height:164,
				x:random(0,Map.width-110),
				y:0,
				img:"images/big_fly.png",
				speed:1
			});
		}
	}
};
